﻿using System;
using DG.Tweening;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace JQMergeFramework
{
    public class UISetting: MonoBehaviour
    {

        public UISwitchChild shakeSc, musicSc, soundSc;


        private void Start()
        {
            UIManager.Instance.AddBtnListener(this.transform);
        }


        public void Open()
        {
            GetComponent<UIPopAnimate>().PopStart();
        }

        void OnBtnClick(Transform trans)
        {
            AudioManager.Instance.Play(AudioName.Click);
            
            AudioManager manager = AudioManager.Instance;
            switch (trans.name)
            {
                
                case "Music":
                    manager.SetMusicOpen(!manager.canPlayMusic);
                    musicSc.index = manager.canPlayMusic ? 0 : 1;
                    break;
                case "Sound":
                    manager.SetSoundOpen(!manager.canPlaySound);
                    soundSc.index = manager.canPlaySound ? 0 : 1;
                    break;
                case "Shake":
                    manager.SetShakeOpen(!manager.canPlayerShake);
                    shakeSc.index = manager.canPlayerShake ? 0 : 1;
                    break;
                case "BtnQuit":
                    DOTween.KillAll();
                    SceneManager.LoadScene("Loading");
                    break;
                case "BtnContinue":
                    Close();
                    break;
            }

        }

        void Close()
        {
            GetComponent<UIPopAnimate>().PopEnd();
        }

    }
}